package com.itheima.test.TCP.fileuploading;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Client {//客服端将文件上传到服务器

    public static void main(String[] args) throws IOException {
        //创建本地字节缓存流
        FileInputStream fis = new FileInputStream("day020\\a.txt");
        BufferedInputStream bis = new BufferedInputStream(fis);

        //创建网络中的流
        Socket socket = new Socket("127.0.0.1", 1000);
        OutputStream out = socket.getOutputStream();

        //读数据,上传数据
        int ch;
        while ((ch = bis.read()) != -1) {
            out.write(ch);//通过网络写到服务器
        }

        //给服务器写下结束标记
        socket.shutdownOutput();

        //接受服务器返回的上传成功
        BufferedReader bw = new BufferedReader(new InputStreamReader(socket.getInputStream(),"UTF-8"));
        String s;
        while ((s =bw.readLine()) != null) {
            System.out.println(s);
        }

        //释放资源
        bis.close();
        fis.close();
        socket.close();
    }
}
